package com.navi.loaddata.loadService.impl.Dcdata;

import com.navi.loaddata.core.etlException.ETLException2;
import com.navi.loaddata.core.gpEntity.MParamD;
import com.navi.loaddata.core.mesEntity.MesCtPospairproduct;
import com.navi.loaddata.core.mesEntity.MesProducthistory;
import com.navi.loaddata.core.mesEntity.SpcDcResultData;
import com.navi.loaddata.core.mesEntity.SpcDcdata;
import com.navi.loaddata.core.mysqlEntity.EtlConfDModel;
import com.navi.loaddata.core.oracleEntity.*;
import com.navi.loaddata.core.oracleEntity.base.EtlParamV;
import com.navi.loaddata.core.util.LoggerUtil;
import com.navi.loaddata.core.util.ProcessUtil;
import com.navi.loaddata.loadDao.SaveBaseDataDao;
import com.navi.loaddata.loadService.impl.baseData.LoadMesBaseDataService;
import com.navi.loaddata.loadService.impl.baseData.ProcessBaseDataService;
import org.apache.commons.collections.map.HashedMap;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static com.navi.loaddata.core.constant.GenericDef.*;
import static java.util.stream.Collectors.groupingBy;

/**
 * @author jay
 */
@Service
public class CheckDcDataService {
    private static final Logger logger = LoggerFactory.getLogger(CheckDcDataService.class);
    private LoggerUtil loggerUtil = new LoggerUtil(this.getClass());

    public boolean[] checkDcData(List<SpcDcResultData> curDcDataList, SpcDcdata spcDc) throws Exception {
        boolean isCheck=true;
        boolean isRawData = false;
        boolean isXData = false;
        boolean isAscData = false;
        int resultListCnt = curDcDataList.size();

        // 数据检查
        SpcDcResultData firstResult = curDcDataList.get(0);
        String firstSiteName = firstResult.getSitename();
        if (ProcessUtil.isNumeric(firstSiteName)) {
            isRawData = true;
        } else if (SITE_X.equals(firstSiteName)) {
            isXData = true;
            if (resultListCnt > 1) {
                logger.warn("DCDATAID={} Site name为X，但是result数量大于1条。", spcDc.getDcdataid());
                isCheck=false;
            }
        } else if (SITE_ASC.equals(firstSiteName)) {
            isAscData = true;
            if (resultListCnt > 1) {
                logger.warn("DCDATAID={} Site name为ASC，但是result数量大于1条。", spcDc.getDcdataid());
                isCheck=false;
            }
        } else {
            logger.warn("DCDATAID={} 无效Site name {}。",  spcDc.getDcdataid(),firstSiteName);
            isCheck=false;
        }
        boolean[] resCheck={isCheck,isRawData,isXData,isAscData};
        return resCheck;
    }
}
